
import 'package:dio/src/form_data.dart' as DioFormData;
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_navigation/get_navigation.dart';
import 'package:work_tools/utils/multipart_file_extended.dart';
import 'package:work_tools/widget/sheets/login_sheet/login_sheet_widget.dart';

class Utils {

  static dynamic syncData(dynamic data) {
    if (data is DioFormData.FormData) {
      DioFormData.FormData formData = DioFormData.FormData();
      formData.fields.addAll(data.fields);
      for (MapEntry mapFile in data.files) {
        final filename = mapFile.value.filename;
        final path = mapFile.value.filePath;
        final multipartFile = MultipartFileExtended.fromFileSync(path, filename: filename);
        formData.files.add(MapEntry(mapFile.key, multipartFile));
      }
      return formData;
    }
    return data;
  }

  static dispatchLogin() async {
    final ctx = Get.context;
    if (ctx == null) {
      print("登录失败");
      return;
    }
    LoginSheetWidget.displaySheet(
      ctx,
      user: "王女士",
      carModelName: "睿蓝7",
      carDesc1: "智能后驱轿跑SUV",
      carDesc2: "智能后驱SUV",
      carImgPath: "",
      wechatMiniPath: '',
      slognPath: '',
    );
  }

}